# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.dwd.tab.dwd_barscan_taking_dt import jms_dwd__dwd_barscan_taking_dt
from jms.dwd.tab.dwd_barscan_warehousing_dt import jms_dwd__dwd_barscan_warehousing_dt
from jms.dwd.tab.dwd_barscan_loading_dt import jms_dwd__dwd_barscan_loading_dt
from jms.dwd.tab.dwd_barscan_sitesend_dt import jms_dwd__dwd_barscan_sitesend_dt
from jms.dwd.tab.dwd_barscan_centersend_dt import jms_dwd__dwd_barscan_centersend_dt
from jms.dwd.tab.dwd_barscan_sitearrival_dt import jms_dwd__dwd_barscan_sitearrival_dt
from jms.dwd.tab.dwd_barscan_centerarrival_dt import jms_dwd__dwd_barscan_centerarrival_dt
from jms.dwd.tab.dwd_barscan_deliver_dt import jms_dwd__dwd_barscan_deliver_dt
from jms.ods.tms.yl_tms_shipment import jms_ods__yl_tms_shipment
from jms.ods.lmdm.yl_lmdm_sys_network import jms_ods__yl_lmdm_sys_network
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dm__dm_collect_trace_dt = SparkSqlOperator(
    task_id='jms_dm__dm_collect_trace_dt',
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_collect_trace_dt_{{ execution_date | cst_ds_nodash }}',
    sql='jms/dm/dm_collect_trace_dt/execute.hql',
    pool_slots=3,
    executor_cores=2,
    executor_memory='3G',
    num_executors=2,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 17,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '1G',  # 堆外内存
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 2,  # 每天至多生成 2 个分区
              'hive.exec.max.dynamic.partitions.pernode': 2,  # 每天至多生成 2 个分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=70),
)

jms_dm__dm_collect_trace_dt << [jms_dwd__dwd_barscan_taking_dt,
                                jms_dwd__dwd_barscan_warehousing_dt,
                                jms_dwd__dwd_barscan_loading_dt,
                                jms_dwd__dwd_barscan_sitesend_dt,
                                jms_dwd__dwd_barscan_centersend_dt,
                                jms_dwd__dwd_barscan_sitearrival_dt,
                                jms_dwd__dwd_barscan_centerarrival_dt,
                                jms_dwd__dwd_barscan_deliver_dt,
                                jms_ods__yl_tms_shipment,
                                jms_ods__yl_lmdm_sys_network, ]
